package thread3;

import java.util.Scanner;

class Counter {
    public volatile int flag = 0;
}

public class Test3 {
    public static void main(String[] args) {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            while (counter.flag == 0) {

            }
            System.out.println("循环结束！");
        });

        Thread t2 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("输入一个整数：");
            counter.flag = scanner.nextInt();
        });

        t1.start();
        t2.start();
    }
}
